module Impressionizer
  module ImpressionsController
    module ClassMethods
      def impressionize(args={})
      end
    end

    module InstanceMethods
      def impressionize
        args = {
          :impressionable_type => controller_name.singularize.capitalize,
          :impressionable_id => params[:id],
          :controller_name => controller_name,
          :action_name => action_name,
          :session_hash => request.session_options['id'],
          :request_hash => ActiveSupport::SecureRandom.hex(187),
          :referrer => request.referer,
          :ip_address => request.remote_ip,
          :user_id => current_user_id
        }
        ActiveSupport::Notifications.instrument("object.information", :args => args)
      end

      private

      def current_user_id
        current_user_id = @current_user ? @current_user.id : nil
        current_user_id = current_user ? current_user.id : nil rescue nil
        current_user_id
      end
    end
  end
end